package com.meitianhui.convenitenbuy.module.store.adapter;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.module.store.model.ShopCarGoods;
import com.meitianhui.convenitenbuy.util.GlideUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/11/24.
 */

public class ShopCarAdapter extends BaseQuickAdapter<ShopCarGoods,BaseViewHolder>{
    private ShopCarAdapterOnClickListener mOnClickListener;
    public ShopCarAdapter( @Nullable List<ShopCarGoods> data) {
        super(R.layout.item_shop_car, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShopCarGoods item) {
        helper.setText(R.id.tv_name,item.getName());
        helper.setText(R.id.tv_price,"¥" +item.getPrice());
        helper.setText(R.id.tv_number,item.getNum());
        helper.setChecked(R.id.cb_choose,item.ischecek());
        GlideUtils.setRectImage(mContext,item.getUrlpic(),R.mipmap.icon_default_picture_store,R.mipmap.icon_default_picture_store,helper.getView(R.id.iv_good_pic));
        //delete
        helper.setOnClickListener(R.id.tv_del, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(mOnClickListener!=null){
                    mOnClickListener.delete(helper.getLayoutPosition());
                }
            }
        });
        //add
        helper.setOnClickListener(R.id.tv_add, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(mOnClickListener!=null){
                    mOnClickListener.add(helper.getLayoutPosition());
                }

            }
        });
        //check
        helper.setOnClickListener(R.id.cb_choose, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(item.ischecek()){
                    if(mOnClickListener!=null){
                        mOnClickListener.isCheck(helper.getLayoutPosition(),true);
                    }
                }else{
                    if(mOnClickListener!=null){
                        mOnClickListener.isCheck(helper.getLayoutPosition(),false);
                    }
                }
            }
        });

    }

    public void setOnClickListener(ShopCarAdapterOnClickListener l) {
        this.mOnClickListener = l;
    }
    public interface ShopCarAdapterOnClickListener {

        void add(int position);
        void delete(int position);
        void isCheck(int position,boolean check);

    }

}
